package com.inspur.edp.common.expr.parser;

import com.inspur.edp.common.expr.ast.CompileUnitParser;
import com.inspur.edp.common.type.DecorationOption;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lizhaorui
 * @date 2025/8/18
 * @description
 */
public class DecoratorParser {

    public static Map<String, DecorationOption> getDecoratorMap(List<CompileUnitParser.DecoratorContext> decoratorContexts) {
        Map<String, DecorationOption> map = new HashMap<>();
        if (decoratorContexts != null && decoratorContexts.size() > 0) {
            for (CompileUnitParser.DecoratorContext decoratorContext : decoratorContexts) {
                String decoratorName = decoratorContext.type().getText();
                List<CompileUnitParser.DecoratorItemContext> items = decoratorContext.decoratorItem();
                Map<String, String> decoratorMap = new HashMap<>();
                for (CompileUnitParser.DecoratorItemContext item : items) {
                    String valueStr = item.express().getText();
                    decoratorMap.put(item.SimpleName().getText(), valueStr.substring(1, valueStr.length() - 1));
                }
                DecorationOption decorationOption = new DecorationOption(decoratorName, decoratorMap);
                map.put(decoratorName, decorationOption);
            }
        }
        return map;
    }

}